package com.mystyle.le.weekproject.fragment;


import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.mystyle.le.weekproject.R;
import com.mystyle.le.weekproject.activity.BaiDuPositionActivity;
import com.mystyle.le.weekproject.activity.CuttorActivity;
import com.mystyle.le.weekproject.activity.DetialActivity;
import com.mystyle.le.weekproject.activity.TalkCollectActivity;
import com.mystyle.le.weekproject.beans.SqliteData;
import com.mystyle.le.weekproject.sqlite.MySqlite;
import com.mystyle.le.weekproject.sqlite.TilkSqlite;
import com.mystyle.le.weekproject.utils.DataCleanManager;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 管理页面
 * A simple {@link Fragment} subclass.
 */
public class ManagerFragment extends Fragment {


    private TextView manage_cartoon_collect;
    private static MySqlite mySqlite;
    private SQLiteDatabase database;
    private TextView duanzi_Collect;
    private TextView baidu_TV;
    private TextView clear_storage;
    private TextView clear_ApplicationData;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mySqlite = new MySqlite(getActivity());
    }

    public ManagerFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_manager, container, false);
        //初始化数据
        initView(view);
        //漫画收藏跳转
        initData();
        //段子收藏跳转
        initChangeTalk();
        //百度地图定位跳转
        initBaiDu();
        //清理内存缓存
        initClearStorage();
        //清除本地缓冲
        initClearApplication();
        return view;
    }

    private void initClearApplication() {
        clear_ApplicationData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DataCleanManager.cleanInternalCache(getActivity());
                DataCleanManager.cleanDatabases(getActivity());
                DataCleanManager.cleanSharedPreference(getActivity());
                Toast.makeText(getActivity(),"清除本地缓冲成功",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initClearStorage() {
        clear_storage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DataCleanManager.cleanDatabases(getActivity());
                Toast.makeText(getActivity(),"清除内存缓冲成功",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initBaiDu() {
        baidu_TV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), BaiDuPositionActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initChangeTalk() {
        duanzi_Collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), TalkCollectActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initData() {
        manage_cartoon_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            Intent intent = new Intent(getActivity(),CuttorActivity.class);
            startActivity(intent);
            }
        });
    }

    private void initView(View view) {
        manage_cartoon_collect = ((TextView) view.findViewById(R.id.manage_cartoon_collect));
        duanzi_Collect = ((TextView) view.findViewById(R.id.duanzi_Collect));
        baidu_TV = ((TextView) view.findViewById(R.id.baidu_TV));
        clear_storage = ((TextView) view.findViewById(R.id.clear_storage));
        clear_ApplicationData = ((TextView) view.findViewById(R.id.clear_ApplicationData));
    }

}
